package com.kugong.anchor;

import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.kugong.util.CommonUtil;
import java.util.Date;
import java.util.List;

/**
 * Created by lenovo on 2015/8/2.
 */
public class AnchorController extends Controller {
    @Clear
    public void index(){
        List<Anchor> anchors = Anchor.dao.qryAnchorStatus();

        for (int i = 0; i < anchors.size(); i++) {
            try {
                Anchor anchor = anchors.get(i);
                String url = anchor.getStr("live_url");
                String comp = anchor.getStr("comp");
                String status = "";
                if(comp.equals("斗鱼")){
                    status = CommonUtil.getDouyu(url);
                }else if(comp.equals("熊猫")){
                    status = CommonUtil.getPanda(url);
                }
                anchor.set("status",status).set("qry_time",new Date()).update();
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        List<Anchor> anchorList = Anchor.dao.qryAllAnchors();
        setAttr("anchorList",anchorList);
        render("index.jsp");
    }
}
